﻿#include<iostream>

using namespace std;

// 产品父类
class AbstractSmile {
public:
    virtual void transform() = 0;
    virtual void ability() = 0;
     //将纯虚析构函数改为虚析构函数
    virtual ~AbstractSmile() {
        cout << "AbstractSmile destructor" << endl;
    }
};

class SheepSmile : public AbstractSmile {
public:
    void transform() override {
        cout << "SheepSmile::transform" << endl;
    }
    void ability() override {
        cout << "SheepSmile::ability" << endl;
    }
    ~SheepSmile() override {
        cout << "SheepSmile destructor" << endl;
    }
};

class LionSmile : public AbstractSmile {
public:
    void transform() override {
        cout << "LionSmile::transform" << endl;
    }
    void ability() override {
        cout << "LionSmile::ability" << endl;
    }
    ~LionSmile() override {
        cout << "LionSmile destructor" << endl;
    }
};

class BatSmile : public AbstractSmile {
public:
    void transform() override {
        cout << "BatSmile::transform" << endl;
    }
    void ability() override {
        cout << "BatSmile::ability" << endl;
    }
    ~BatSmile() override {
        cout << "BatSmile destructor" << endl;
    }
};

// 定义工厂类 在简单工厂模式中 工厂类有且仅有一个

// 强类型枚举 enum+class/struct char指令底层为char型 Sheep Lion Bat仅仅是个符号
enum class Type : char { Sheep, Lion, Bat };

class SmileFactory {
public:
    // 多态
    AbstractSmile* createSmile(Type type) {
        AbstractSmile* ptr = nullptr;
        switch (type)
        {
        case Type::Sheep:
            ptr = new SheepSmile;
            break;
        case Type::Lion:
            ptr = new LionSmile;
            break;
        case Type::Bat:
            ptr = new BatSmile;
            break;
        default:
            break;
        }
        return ptr;
    }
};

//int main() {
//    SmileFactory* factory = new SmileFactory;
//    AbstractSmile* ptr = factory->createSmile(Type::Sheep);
//    ptr->transform();
//    ptr->ability();
//
//    // 释放内存
//    delete ptr;
//    delete factory;
//
//    return 0;
//}